package com.young.cms.model.gen4;

import com.young.cms.model.Table;
import com.young.cms.model.enums.EGenExtendTagEnum;
import com.young.cms.model.enums.ETableFirstColumnTypeEnum;
import com.young.cms.util.CmsConstants;
import com.young.common.core.excel.ExcelColumn;
import com.young.common.util.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
* 代码生成主体信息实体类
* Created by rookie on 2018-7-11.
*/
public class GenMainV4 {

    private String id;//代码生成编号

    private String name;//代码生成名称

    private String tableName;//表名

    private String className;//实体类名

    private String packageName;//包名

    private String moduleName;//模块名

    private String tableRemark;//表说明

    private String logService;//日志服务

    private String savePath;//保存路径

    private String author;//作者

    private String createUserId;//创建人编号,关联用户表

    private String createUserName;//创建人姓名

    private Date createTime;//创建时间

    private Date updateTime;//修改时间

    private String webDomain;//服务域名
    private String extendTag;//扩展标记
    private String[] extendTagArr;//扩展标记

    private List<GenColV4> colList;//字段配置
    /**
     * 主键的java类型
     */
    private String primaryKeyJavaType = "String";
    /**
     * 表格首列类型
     */
    private String tableFirstColumnType;
    /**
     * 表单项标题未知
     */
    private String formTitlePosition;
    /**
     * 表单项标题宽度
     */
    private String formTitleWidth;

    public GenMainV4(){
        super();
    }

    public static GenMainV4 buildDefault(Table table) {
        GenMainV4 genMainV4 = new GenMainV4();
//        genMain.setId();
        genMainV4.setName(table.getName());
        genMainV4.setTableName(table.getId());
        genMainV4.setClassName(StringUtils.toFirstUpperCamel(table.getId()));
        genMainV4.setPackageName("com.young");
        genMainV4.setModuleName("");
        genMainV4.setTableRemark(table.getName());
        genMainV4.setLogService("1");
        genMainV4.setSavePath("C:/youngCodeGenerate");
        genMainV4.setAuthor("");
//        genMain.setCreateUserId();
//        genMain.setCreateUserName();
//        genMain.setCreateTime();
//        genMain.setUpdateTime();
//        genMain.setColList();
        genMainV4.setWebDomain(CmsConstants.DOMAIN_LIST[0]);
        genMainV4.setPrimaryKeyJavaType("");
        genMainV4.setExtendTagArr(new String[]{EGenExtendTagEnum.IMPORT.tag, EGenExtendTagEnum.EXPORT.tag, EGenExtendTagEnum.EXTENDS_DB_SORT_DO.tag, EGenExtendTagEnum.VIEW_OPER_EDIT.tag, EGenExtendTagEnum.VIEW_OPER_DEL.tag});
        genMainV4.setExtendTag(String.join(",", genMainV4.getExtendTagArr()));

        genMainV4.setTableFirstColumnType(ETableFirstColumnTypeEnum.CHECKBOX.getType());
        genMainV4.setFormTitlePosition("left");
        genMainV4.setFormTitleWidth("100px");
        return genMainV4;
    }

    /**
     * 表名转为类名
     */
    public void convertClassName() {
        String[] arr = this.getTableName().split("_");
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < arr.length; i++) {
            //单词首字母大写
            sb.append(arr[i].substring(0, 1).toUpperCase()).append(arr[i].substring(1).toLowerCase());
        }
        this.setClassName(sb.toString());
    }

    /**
     * 添加字段配置
     * @param genColV4
     */
    public void addCol(GenColV4 genColV4){
        if (this.colList == null){
            this.colList = new ArrayList<GenColV4>();
        }
        this.colList.add(genColV4);
    }

    /**
     * 批量添加字段配置
     * @param genColV4List
     */
    public void addCol(List<GenColV4> genColV4List){
        if (this.colList == null){
            this.colList = genColV4List;
        }else if (genColV4List != null){
            for(GenColV4 genColV4 : genColV4List){
                this.colList.add(genColV4);
            }
        }
    }

    public boolean isSupportImport() {
        return EGenExtendTagEnum.IMPORT.in(this.extendTag);
    }
    public boolean isSupportExport() {
        return EGenExtendTagEnum.EXPORT.in(this.extendTag);
    }
    public boolean isSupportBaseDO() {
        return EGenExtendTagEnum.EXTENDS_BASE_DO.in(this.extendTag) || isSupportFillBaseDO();
    }
    public boolean isSupportFillBaseDO() {
        return EGenExtendTagEnum.FILL_BASE_DO.in(this.extendTag);
    }
    public boolean isSupportDbSortDO() {
        return EGenExtendTagEnum.EXTENDS_DB_SORT_DO.in(this.extendTag);
    }

    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getTableName() {
        return tableName;
    }
    public void setTableName(String tableName) {
        this.tableName = tableName;
    }
    public String getClassName() {
        return className;
    }
    public void setClassName(String className) {
        this.className = className;
    }
    public String getPackageName() {
        return packageName;
    }
    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }
    public String getModuleName() {
        return moduleName;
    }
    public void setModuleName(String moduleName) {
        this.moduleName = moduleName;
    }
    public String getTableRemark() {
        return tableRemark;
    }
    public void setTableRemark(String tableRemark) {
        this.tableRemark = tableRemark;
    }
    public String getLogService() {
        return logService;
    }
    public void setLogService(String logService) {
        this.logService = logService;
    }
    public String getSavePath() {
        return savePath;
    }
    public void setSavePath(String savePath) {
        this.savePath = savePath;
    }
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
    public String getCreateUserId() {
        return createUserId;
    }
    public void setCreateUserId(String createUserId) {
        this.createUserId = createUserId;
    }
    public String getCreateUserName() {
        return createUserName;
    }
    public void setCreateUserName(String createUserName) {
        this.createUserName = createUserName;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public List<GenColV4> getColList() {
        return colList;
    }

    public void setColList(List<GenColV4> colList) {
        this.colList = colList;
    }

    public String getWebDomain() {
        return webDomain;
    }

    public void setWebDomain(String webDomain) {
        this.webDomain = webDomain;
    }

    public String getPrimaryKeyJavaType() {
        return primaryKeyJavaType;
    }

    public void setPrimaryKeyJavaType(String primaryKeyJavaType) {
        this.primaryKeyJavaType = primaryKeyJavaType;
    }

    public String getExtendTag() {
        return extendTag;
    }

    public void setExtendTag(String extendTag) {
        this.extendTag = extendTag;
    }

    public String[] getExtendTagArr() {
        return extendTagArr;
    }

    public void setExtendTagArr(String[] extendTagArr) {
        this.extendTagArr = extendTagArr;
    }

    public String getTableFirstColumnType() {
        return tableFirstColumnType;
    }

    public void setTableFirstColumnType(String tableFirstColumnType) {
        this.tableFirstColumnType = tableFirstColumnType;
    }

    public String getFormTitlePosition() {
        return formTitlePosition;
    }

    public void setFormTitlePosition(String formTitlePosition) {
        this.formTitlePosition = formTitlePosition;
    }

    public String getFormTitleWidth() {
        return formTitleWidth;
    }

    public void setFormTitleWidth(String formTitleWidth) {
        this.formTitleWidth = formTitleWidth;
    }
}